//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "Graphics/Resources/Font.h"

namespace Engine
{
namespace Graphics
{


	//
	// Bitmap Font
	//

	class BitmapFont : public IFont
	{
		friend struct FontLoader;

	// types
	public:
		typedef static_array< Glyph, 256 >		glyph_array_t;


		//
		// Font Load Parameters
		//
		struct BitmapFontLoadParams : ResLoadParams
		{
		// variables
		public:
			uint	height;
			bool	mipmaps;

		// methods
		public:
			BitmapFontLoadParams () : ResLoadParams( Signature() ), height(32), mipmaps(false)
			{}

			static signature_t Signature ()
			{
				return CompileTime::TSignature8< 'G', 'B', 'M', 'P', 'F', 'O', 'N', 'T' >::value;
			}
		};

	private:
		struct GlyphReader;


	// variables
	protected:
		glyph_array_t	_glyphs;
		Texture			_texture;
		float			_baseLineTopMargin;
		uint			_height;			// height of font in pixels


	// methods
	public:
		BitmapFont (const EngineSubSystemsRef ess, EResource::type resType = EResource::BITMAP_FONT);
		~BitmapFont ();
		
		void Draw (const FontBatch &params, const vec2 &pos, uni_c_string text, bool scissor) override;
		void Draw (const FontBatch &params, const rect &region, uni_c_string text, bool scissor) override;
		
		void Draw (const FontBatch &params, const vec2 &pos, const ext_string &text, bool scissor) override;
		void Draw (const FontBatch &params, const rect &region, const ext_string &text, bool scissor) override;

		void GetTextDimensions (const FontBatch &params, uni_c_string text, OUT vec2 &dim, OUT usize &lineLength) override;
		
		void GetFormattedText (const FontBatch &params, float maxLineWidth, const ext_string &text,
								const LocaleCharacters &localeChars, OUT ext_string &formattedText, OUT vec2 &dim) override;

		TexturePtr	GetTexture ()					{ return &_texture; }

		uint  GetHeightInPixels () const			{ return _height; }
		
		float GetDefaultScale () const;
		

		// Resource //
		virtual bool SwapData (const ResourcePtr &) override;
		
		virtual bool IsLoadedWithParams (const ResLoadParams &params) const override;

		virtual bool IsValid () const override;


		static BitmapFontPtr	New (const EngineSubSystemsRef ess);

		static BitmapFontLoadParams	GetDefaultLoadParams ();


	private:
		void _CalcMemSize ();
	};

	
}	// Graphics
}	// Engine